home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
telecom
/
24
/
games
/
makemaze.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-06-19
|
7KB
|
207 lines
PROGRAM MAZE_MAKER; { V.1.0 last update 5/30/86 }
{ By Steve Pauley }
CONST
{$I gemconst}
Num_Size = 10; { string size }
TYPE
{$I gemtype}
VAR
Maze_One : ARRAY[ 1..81,1..49 ] OF Byte; { maze 1 array }
X,Y,Z : integer;
R_Num : Integer; { used by One_To_Four }
X_Direct : ARRAY[ 1..5 ] OF Integer; { look-up forward move }
Y_Direct : ARRAY[ 1..5 ] OF Integer; { look-up forward move }
X_Back : ARRAY[ 1..5 ] OF Integer; { look-up move back }
Y_Back : ARRAY[ 1..5 ] OF Integer; { look-up move back }
{$I gemsubs}
FUNCTION random: Integer; { returns a randon integer + or - }
XBIOS(17);
PROCEDURE Set_Up; { assign values for Direction look-up table }
BEGIN
X_Direct[ 1 ] := 0; { forward x value }
X_Direct[ 2 ] := 2;
X_Direct[ 3 ] := 0;
X_Direct[ 4 ] := -2;
X_Direct[ 5 ] := 0;
Y_Direct[ 1 ] := -2; { forward y value }
Y_Direct[ 2 ] := 0;
Y_Direct[ 3 ] := 2;
Y_Direct[ 4 ] := 0;
Y_Direct[ 5 ] := 0;
X_Back[ 1 ] := 0; { back-up x value }
X_Back[ 2 ] := -2;
X_Back[ 3 ] := 0;
X_Back[ 4 ] := 2;
X_Back[ 5 ] := 0;
Y_Back[ 1 ] := 2; { back-up y value }
Y_Back[ 2 ] := 0;
Y_Back[ 3 ] := -2;
Y_Back[ 4 ] := 0;
Y_Back[ 5 ] := 0;
END; { Set_Up }
PROCEDURE One_To_Four; { makes a random number from 1 - 4 }
VAR
Num_Long : Long_Integer;
Num_Short : Integer;
BEGIN
REPEAT
Num_Short := random;
Num_Long := ABS( Num_Short );
Num_Long := Num_Long DIV 6554;
Num_Short := INT( Num_Long );
UNTIL ( Num_Short > 0 ) AND ( Num_Short < 5 );
R_Num := Num_Short;
END; { of One_To_Four }
PROCEDURE Kolors; { Set new colors in color registers }
CONST
Zero= 0; { values for color registers }
One = 150;
Two = 300;
Three= 400;
Four = 550;
Five = 650;
Six = 800;
Seven= 900;
BEGIN
Set_Color( 0,Seven,Seven,Seven ); { set background to black }
Set_Color( 1,Seven,Zero,Zero ); { set to red }
Set_Color( 2,Zero,Seven,Zero ); { set to Green }
Set_Color( 3,Zero,Zero,Seven ); { set to Blue }
Set_Color( 4,Seven,Two,Zero );
Set_Color( 5,Zero,Zero,Zero );
Set_Color( 6,Seven,Zero,Four );
Set_Color( 7,Six,One,Six );
Set_Color( 8,Four,One,Seven );
Set_Color( 9,Three,Three,Seven );
Set_Color( 10,Zero,Five,Five );
Set_Color( 11,Zero,Seven,Four );
Set_Color( 12,Four,Seven,Zero );
Set_Color( 13,Zero,Zero,Two );
Set_Color( 14,Two,Two,Six );
Set_Color( 15,Four,Four,Seven );
END; { of Kolors }
PROCEDURE Clean_Screen;
BEGIN
Draw_Mode( 1 );
Paint_Color( 0 );
Paint_Rect( 0,0,320,200 );
END; { of Clean_Screen }
PROCEDURE Make_Maze_One;
VAR
D_Num,Rotate :Integer; { direction numbers }
LX,LY :Integer; { loop control var }
New_X,New_Y :Integer; { new location to check }
Half_X,Half_Y :Integer; { halfway between X and New_X, Y and New_Y }
BEGIN
Draw_Mode( 1 ); { replace mode }
Paint_Color( 5 ); { maze wall color }
Paint_Rect( 0,0,319,190 ); { paint complete maze area wall color }
Paint_Color( 0 ); { black for path color }
FOR LX := 1 TO 81 DO { store 255 in every element of array }
BEGIN
FOR LY := 1 TO 49 DO
BEGIN
Maze_One[ LX,LY ] := 255;
END;
END;
FOR LX := 1 TO 81 DO { store 0 around outside edge of array }
BEGIN
Maze_One[ LX,1 ] := 0;
Maze_One[ Lx,49 ] := 0;
END;
FOR LY := 1 TO 49 DO
BEGIN
Maze_One[ 1,LY ] := 0;
Maze_One[ 81,LY ] := 0;
END;
Maze_One[ 3,2 ] := 0; { start location or hole in wall }
Paint_Rect( 3*4-8, 2*4-8, 6, 6 );
X := 3; { starting location of maze path }
Y := 3;
Maze_One[ X,Y ] := 5; { start marker }
Paint_Rect( X*4-8, Y*4-8, 6, 6 );
D_Num := 3; { start with down direction }
REPEAT { maze calculating main loop }
One_To_Four; { get a random number from 1 to 4 }
IF R_Num < 3 THEN Rotate := 1; { direction rotate clock wise }
IF R_Num > 2 THEN Rotate := -1; { direction rotate counter clock wise }
One_To_Four; { get a random number from 1 to 4 }
D_Num := R_Num; { copy new random number to direction number }
REPEAT
D_Num := D_Num + Rotate ; { rotate to new direction }
IF D_Num > 4 THEN D_Num := 1; { make sure it is one of 4 ways }
IF D_Num < 1 THEN D_Num := 4;
New_X := X + X_Direct[ D_Num ]; { calculate next location to check }
New_Y := Y + Y_Direct[ D_Num ];
{ if new location is open or we have tried all 4 ways, stop checking }
UNTIL ( D_Num = R_Num ) OR ( Maze_One[ New_X,New_Y ] = 255 );
IF Maze_One[ New_X,New_Y ] = 255 THEN { new direction is unused }
BEGIN { add new section to path }
Maze_One[ New_X,New_Y ] := D_Num; { store direction marker }
Half_X := ( ( New_X+X ) DIV 2 ); { find wall between new ... }
Half_Y := ( ( New_Y+Y ) DIV 2 ); { location and old path }
Maze_One[ Half_X,Half_Y ] := 0; { and store a zero }
{ paint the new path }
Paint_Rect( New_X*4-8, New_Y*4-8, 6, 6 );
Paint_Rect( Half_X*4-8,Half_Y*4-8, 6, 6 );
X := New_X; { update position pointers }
Y := New_Y;
END
ELSE BEGIN { no new path direction left open }
D_Num := Maze_One[ X,Y ]; { read old direction pointer }
Maze_One[ X,Y ] := 0; { this path is deadend so erase marker }
X := X + X_Back[ D_Num ]; { move position pointer back to ...}
Y := Y + Y_Back[ D_Num ]; { previous location }
END;
UNTIL D_Num = 5; { if we are back to start marker maze is finished }
Maze_One[ 79,48 ] := 0; { start location or hole in wall }
Paint_Rect( 79*4-8, 48*4-8, 6, 6 );
END; { of Make_Maze_One }
BEGIN { PROGRAM }
IF Init_Gem >= 0 THEN
BEGIN
{ start program here }
Hide_Mouse;
Kolors; { set all color registers }
Set_Up; { assign values to direction arrays }
Clean_Screen; { draw a big black square }
Draw_String( 0,198,'MAZE MAKER - by S. Pauley' );
Make_Maze_One; { calculate and draw the first maze }
REPEAT
Draw_String( 0,198,'ALT & HELP to PRINT - OTHER KEYS EXIT' );
UNTIL Keypress;
Show_Mouse;
Set_Color( 0,950,950,950 ); { turn screen white before we stop }
Set_Color( 1,0,0,0 ); { turn mouse & text color back to black }
Exit_Gem ;
END ;
END.